<template>
  <div>
    <!-- 列表组件 -->
    <el-table :data="menulist" border style="width: 100%" row-key="id">
      <el-table-column prop="id" label="菜单编号" width="180">
      </el-table-column>
      <el-table-column prop="title" label="菜单名称" width="180">
      </el-table-column>
      <el-table-column prop="pid" label="上级菜单"> </el-table-column>
      <el-table-column prop="icon" label="菜单图标"> </el-table-column>
      <el-table-column prop="url" label="菜单地址"> </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="item">
          <span v-if="item.row.status == 1">正常</span>
          <span v-else>禁用</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="item">
          <el-button
            class="btnInfo"
            type="primary"
            icon="el-icon-edit"
            size="mini"
            circle
            @click="edit(item.row.id)"
          ></el-button>
          <el-button
            class="btnInfo"
            type="danger"
            icon="el-icon-delete"
            size="mini"
            circle
            @click="del(item.row.id)"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { mapActions, mapGetters } from "vuex";
import { menuDel } from "../../request/api.js";
export default {
  data() {
    return {
      list: [],
    };
  },
  mounted() {
    this.getMenu();
  },
  methods: {
    // 删除
    del(id) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          menuDel({ id: id }).then((res) => {
            console.log(res);
            if (res.code == 200) {
              this.$message.success(res.msg);
              this.getMenu();
            } else {
              this.$message.error(res.msg);
              
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    //点击编辑按钮事件
    edit(id) {
      this.$emit("edit", id);
    },
    ...mapActions({
      getMenu: "menu/getMenuList",
    }),
  },
  computed: {
    ...mapGetters({
      menulist: "menu/getmenus",
    }),
  },
  mounted() {},
};
</script>

<style scoped></style>
